<template>
  <el-dialog
    :title="dialog.title"
    :visible.sync="dialog.show"
    width="530px"
    custom-class="mydialog"
    append-to-body
    @close="handleClose"
  >
    <div class="dialog-content">
      <el-form ref="form1" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="姓名："><el-input v-model="dialog.userName"/></el-form-item>
        <el-form-item label="电话："><el-input v-model="dialog.phone"/></el-form-item>
        <el-form-item label="收货地址："><el-input v-model="dialog.address"/></el-form-item>
      </el-form>
      <div class="text-center mt-30">
        <el-button class="greenbt" type="primary" @click="updateRecord()">修改</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { updateReceivingGoods } from '@/api/pas/delivery'
export default {
  props: {
    modalStaticData: {
      type: Object,
      default: () => {}
    },
    // 父组件调用时传进来的参数
    modalData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      dialog: {
        userName: '',
        show: true,
        phone: '',
        address: '',
        orderNumber: ''
      },
      rules: {}
    }
  },
  mounted() {
    // 基本信息
    this.dialog.userName = this.modalData.userName
    this.dialog.phone = this.modalData.phone
    this.dialog.address = this.modalData.address
    this.dialog.orderNumber = this.modalData.orderNumber
  },
  methods: {
    handleClose() {
      this.$emit('close')
      this.modalStaticData.closeChildAndRefresh()
    },
    // 修改
    updateRecord() {
      if (this.dialog.userName === null || this.dialog.userName === '' ||
      this.dialog.phone === null || this.dialog.phone === '' ||
      this.dialog.address === null || this.dialog.address === '') {
        this.$message({
          message: '姓名、电话、地址不能为空',
          type: 'warning'
        })
        return
      }
      var param = {
        'userName': this.dialog.userName,
        'phone': this.dialog.phone,
        'address': this.dialog.address,
        'orderNumber': this.dialog.orderNumber
      }
      updateReceivingGoods(param)
        .then(response => {
          this.handleClose()
          if (response.data.status === 'success') {
            this.$message({
              message: response.data.messge,
              type: 'success'
            })
          } else {
            this.$message({
              message: response.data.messge,
              type: 'warning'
            })
          }
        })
        .finally(() => {
          this.modalStaticData.closeChildAndRefresh()
        })
    }
  }
}
</script>
